﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

//main83&84：多级指针
int main83()
{
	int a = 10;
	int* p = &a;
	int** pp = &p;
	//1.二级指针pp指向的是，一级指针p的地址，*pp可以取出pp地址对应的p的地址值；
		//二级指针pp，前面加*，代表一级指针p的值；
	//*pp == *p; **p == &a;
	//2.二级指针pp前面加**，代表指针pp指向一级指针p指向地址对应的内存值a;
	**pp = 20;


	system("pause");
	return EXIT_SUCCESS;
}
int main84(void)
{
	int a = 10;
	int* p = &a;
	int** pp = &p;
	int*** ppp = &pp;
	//ppp = &pp;
	//*ppp = pp = &p;
	//**ppp = *pp = p = &a;
	//***ppp = **pp = *p = a;

	//*pppp = ppp = &pp;
	//**pppp = *ppp = pp = &p;
	//***pppp = **ppp = *pp = p = &a;
	//****pppp = ***ppp = **pp = *p = a;

	printf("3.输出二级指针的内存大小：%d\n", sizeof(int**));//4
	printf("4.输出三级指针的内存大小：%d\n", sizeof(int***));//4
	printf("5.输出万能指针的内存大小：%d\n", sizeof(void*));//4

	int b = 10;
	char* pChar = &b;
	//*pChar = 1000; 232
	*(int*)pChar = 1000;//1000
	printf("6.使用char*类型的指针去改变int类型变量a的值，*pChar的值不能超过-128~127，必须强转成int*：%d\n", b);//232-->1000

	int arr[] = { 1,2,3 };
	char* pArr = arr;
	*(int*)pArr = 100;
	printf("7.强转char*类型的指针pArr为int*类型，改变数组的元素值，则arr[0]为：%d\n", arr[0]);//100
	*((int*)pArr + 1) = 200;
	printf("8.强转char*类型的指针pArr为int*类型，改变数组的元素值，则arr[1]为：%d\n", arr[1]);//200
	*((int*)pArr + 2) = 300;
	printf("9.强转char*类型的指针pArr为int*类型，改变数组的元素值，则arr[2]为：%d\n", arr[2]);//300

	printf("10.输出arr[0]的地址值：%d\n", &arr[0]);//5242276
	printf("11.输出arr[0]+1的地址值，其实就是arr[1]的地址值：%d\n", &arr[0] + 1);//5242280

	int* p1 = arr;
	int* p2 = &arr[1];
	int len = p2 - p1;
	//13.这个差值，并不是内存大小，而是一个int类型大小，相隔的元素个数；
	printf("12.输出数组arr两个相邻元素地址值的差：%d\n", len);//1

	return 0;
}